import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'
import clueCustomerMgr from '@/biz/customer/clueCustomer.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'customerPhone',
        minWidth: 120,
        header: {
          filter: {
            key: 'customerPhone',
            title: '人员手机号',
            placeholder: '请输入人员手机号',
            input: {}
          }
        }
      },
      {
        title: '客户姓名',
        field: 'customerName',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '所属组织',
        field: 'orgName',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '所属案场',
        field: 'buildingName',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '所属地域',
        field: 'address',
        minWidth: 180,
        align: 'center'
      },
      {
        title: '客户意向等级',
        field: 'intentionLevelName',
        minWidth: 180,
        align: 'center',
        header: {
          filter: {
            title: '客户意向等级',
            key: 'intentionLevelName',
            placeholder: '请选择',
            select: {
              options: [
                { key: 'A', value: 'A' },
                { key: 'B', value: 'B' },
                { key: 'C', value: 'C' },
                { key: 'D', value: 'D' }
              ],
              multiple: true
            }
          }
        }
      },
      {
        title: '释放前最近到访日期',
        field: 'visitTime',
        minWidth: 180,
        align: 'center'
      },
      {
        title: '释放前最近签约日期',
        field: 'signingTime',
        minWidth: 180,
        align: 'center'
      },
      {
        title: '释放前归属顾问',
        minWidth: 150,
        align: 'center',
        header: {
          filter: {
            title: '释放前归属顾问',
            key: 'oldUserNameOrWorkNumber',
            placeholder: '请选择释放前归属顾问',
            load: (o) => {
              o.select.options = clueCustomerMgr.selectTeamUser()
            },
            select: {
              options: [],
              multiple: false,
              filterable: true,
              remote: (key) => {
                return clueCustomerMgr.selectTeamUser(key)
              }
            }
          }
        },
        cell: {
          value: (row) => {
            return `${
              row.oldUserName
                ? row.oldUserWorkNumber
                  ? row.oldUserName + '(' + row.oldUserWorkNumber + ')'
                  : row.oldUserName
                : '-'
            }`
          },
          text: {
            tooltip: false
          }
        }
      },
      {
        title: '释放入池日期',
        field: 'joinPoolDate',
        minWidth: 180,
        align: 'center',
        header: {
          filter: dateOpt.range({
            title: '释放入池日期',
            placeholder: '请选择释放入池日期',
            startKey: 'joinPoolDateStart',
            endKey: 'joinPoolDateEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.joinPoolDateStart, val.joinPoolDateEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('释放入池日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.joinPoolDateStart, val.joinPoolDateEnd).Y >= 2)
            }
          })
        }
      },
      {
        title: '释放原因',
        field: 'joinPoolReasonName',
        minWidth: 120,
        align: 'center',
        header: {
          filter: {
            title: '释放原因',
            key: 'joinPoolReason',
            placeholder: '请选择',
            select: {
              options: [
                { key: 2, value: '离案' },
                { key: 3, value: '过期' },
                { key: 1, value: '无效' }
              ]
            }
          }
        }
      },
      {
        title: '置业目的',
        field: 'intentionPurpose',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '意向总价',
        field: 'intentionTotalPrice',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '意向面积',
        field: 'intentionArea',
        minWidth: 120,
        align: 'center'
      }
    ]
  }
}

export default Column
